<template>
	<div v-if="isShow">
		<view class="wrap-evaluate-pop" @touchmove.stop.prevent @click.stop="onDismiss">
			<view class="evaluate-white safe-area flex column align-center" @click.stop.prevent>
				<image class="evaluate-close" @click.stop="onDismiss" :src="getImageURL('common/close.png')" />

				<view class="evaluate-title f-32 fBold"> 技师评价 </view>

				<view class="evaluate-user flex align-center">
					<image class="avatar" :src="userInfo.work_image" />

					<view class="user-right">
						<view class="right-info flex align-center">
							<view class="nickname limit-num-line f-30 fBold">
								{{ userInfo.name }}
							</view>
							<view class="time f-26"> 从业{{ userInfo.practise_year }}年 </view>
						</view>

						<view class="right-content f-26">
							{{ userInfo.service_introduction }}
						</view>
					</view>
				</view>

				<scroll-view scroll-y class="evaluate-list" @scrolltolower="onLoadMore">
					<block v-for="(item, index) in commentList" :key="index">
						<view class="item flex align-start">
							<image class="avatar" :src="item.user.avatar" />

							<view class="item-right">
								<view class="nickname-time flex align-center just-between">
									<view class="nickname limit-num-line f-28">
										{{ item.user.nickname }}
									</view>

									<view class="time f-24">
										{{ item.createtime }}
									</view>
								</view>

								<view class="star-bg flex align-center">
									<block v-for="i in parseInt(item.star)" :key="i">
										<image class="star" :src="getImageURL('common/star.png')" />
									</block>
								</view>

								<view class="item-content f-26">
									{{ item.content }}
								</view>

								<view class="labels-bg flex" v-if="item.commentlabel.length > 0">
									<block v-for="(label, idx) in item.commentlabel" :key="idx">
										<view class="labels-item f-26">
											{{ label.label.name }}
										</view>
									</block>
								</view>
							</view>
						</view>
					</block>

					<uEmpty v-if="commentList.length === 0" />
				</scroll-view>
			</view>
		</view>
	</div>
</template>

<script>
	import { getTechnicianCommentData } from "@/API/home.js";
	export default {
		props: {
			/**
			 * 是否显示
			 */
			isShow: {
				type: Boolean,
				default: false,
			},
			/**
			 * 技师ID
			 */
			technicianID: {
				type: String,
				default: "",
			},
		},
		data() {
			return {
				userInfo: { work_image: "" },
				page: 1,
				total: 0,
				commentList: [],
			};
		},
		watch: {
			technicianID: {
				handler() {
					this.onRefresh();
				},
			},
		},
		methods: {
			/**
			 * 关闭弹窗
			 */
			onDismiss() {
				this.$emit("update:isShow", false);
			},
			/**
			 * 重新加载
			 */
			onRefresh() {
				this.page = 1;
				this.commentList = [];
				this.getData();
			},
			/**
			 * 加载更多
			 */
			onLoadMore() {
				if (this.commentList.length < this.total) {
					this.page++;
					this.getData();
				}
			},
			/**
			 * 网络请求
			 */
			getData() {
				getTechnicianCommentData(this.technicianID, this.page).then((res) => {
					this.total = res.data.list.total;
					const list = res.data.list.data;
					if (this.page === 1) {
						this.userInfo = res.data.technician;
						this.commentList = list;
					} else {
						this.commentList = this.commentList.concat(list);
					}
				});
			},
		},
	};
</script>

<style lang="scss" scoped>
	.wrap-evaluate-pop {
		position: fixed;
		left: 0;
		top: 0;
		width: 100vw;
		height: 100vh;
		z-index: 1000;
		background-color: rgba(0, 0, 0, 0.5);

		.evaluate-white {
			position: absolute;
			left: 0;
			bottom: 0;
			width: 100vw;
			background-color: white;
			z-index: 1001;
			padding: 30rpx 20rpx 20rpx;
			box-sizing: border-box;

			.evaluate-close {
				position: absolute;
				right: 20rpx;
				top: 28rpx;
				width: 40rpx;
				height: 40rpx;
				z-index: 1002;
			}

			.evaluate-title {
				color: $title-color;
			}

			.evaluate-user {
				margin-top: 30rpx;
				width: 100%;
				overflow: hidden;
				padding-bottom: 30rpx;
				border-bottom: 2rpx solid $separa-color;

				.avatar {
					width: 82rpx;
					height: 82rpx;
					border-radius: 50%;
					overflow: hidden;
				}
				.user-right {
					margin-left: 20rpx;
					flex: 1;
					overflow: hidden;

					.right-info {
						width: 100%;
						overflow: hidden;

						.nickname {
							--limit-num: 1;
							color: $title-color;
						}
						.time {
							margin-left: 12rpx;
							color: $sub-title-color;
						}
					}
					.right-content {
						margin-top: 15rpx;
						color: #666666;
						line-height: 40rpx;
					}
				}
			}

			.evaluate-list {
				width: 100%;
				height: 600rpx;
				overflow: hidden;

				.item {
					width: 100%;
					overflow: hidden;
					border-bottom: 2rpx solid $separa-color;
					padding: 30rpx 0rpx 30rpx 0rpx;

					&:last-child {
						border-bottom: none;
					}

					.avatar {
						width: 62rpx;
						height: 62rpx;
						border-radius: 50%;
						overflow: hidden;
					}

					.item-right {
						margin-left: 20rpx;
						flex: 1;
						overflow: hidden;

						.nickname-time {
							width: 100%;
							overflow: hidden;

							.nickname {
								margin-right: 10rpx;
								flex: 1;
								--limit-num: 1;
								color: $title-color;
							}
							.time {
								color: $old-price-color;
							}
						}

						.star-bg {
							margin-top: 5rpx;
							width: 100%;
							overflow: hidden;

							.star {
								width: 24rpx;
								height: 24rpx;
								margin-right: 4rpx;
								&:last-child {
									margin-right: 0rpx;
								}

								> image {
									width: 100%;
									height: 100%;
								}
							}
						}

						.item-content {
							margin-top: 20rpx;
							width: 100%;
							overflow: hidden;
							color: $old-price-color;
							line-height: 40rpx;
						}

						.labels-bg {
							margin-top: 20rpx;
							margin-left: -16rpx;
							width: calc(100% + 16rpx);
							flex-wrap: wrap;
							margin-bottom: -20rpx;

							.labels-item {
								margin-left: 16rpx;
								margin-bottom: 20rpx;
								height: 40rpx;
								line-height: 40rpx;
								text-align: center;
								padding: 0 18rpx;
								border-radius: 20rpx;
								overflow: hidden;
								background: $separa-color;
								color: $old-price-color;
							}
						}
					}
				}
			}
		}
	}
</style>
